package com.ahncnk.powermonitor.admin.devices.controller;

import com.ahncnk.powermonitor.admin.devices.domain.entity.Device;
import com.ahncnk.powermonitor.admin.devices.domain.projection.GeoDevice;
import com.ahncnk.powermonitor.admin.devices.service.DeviceService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * DeviceController
 *
 * @author lipei
 */
@RestController
public class DeviceController {
    @Resource
    private DeviceService deviceService;

    @GetMapping(path = "/api/devices")
    public Page<Device> search(String name, String sn, Boolean offline, Pageable pageable) {
        return deviceService.search(name, sn, offline, pageable);
    }

    @GetMapping(path = "/api/geo-devices")
    public Iterable<GeoDevice> listGeoDevices(@RequestParam String district) {
        return deviceService.listGeoDevices(district);
    }
}
